
/****
 * Copyright (C) 2006 dNux Team
 *                                                            ****
 * This program is free software; you can redistribute it and/or *
 * modify under the terms of the GNU General Public License as   *
 * published by the Free Software Foundation;                    *
 * either version 2 of the License.                              *
 *                                                               *
 * This program is distributed in the hope that it will be       *
 * useful, but WITHOUT ANY WARRANTY; without even the implied    *
 * warranty of without even the implied waranty of               *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.          *
 * See the GNU General Public License for more details.          *
 *                                                               *
 * You should have received a copy of the                        *
 * GNU General Public License                                    *
 * along with this program; if not, write to the                 *
 * Free Software Foundation, Inc.,                               *
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. *
 *                                                               *
 ****                                                         ****/

#include "dcore.h"

d_map_data_t *
d_map_data_new(char *key, void *value, d_map_free_f f_free)
{
  d_map_data_t *new = (d_map_data_t *) malloc(sizeof(d_map_data_t));
  new->key = strdup(key);
  new->value = value;
  new->f_free = f_free;
  return new;
}

void
d_map_data_free(void *pointer)
{
  d_map_data_t *data = (d_map_data_t *) pointer;

  if (data->f_free) data->f_free(data->value);
  if (data->key) free(data->key);
  if (data) free(data);
}

d_map_iterator_t *
d_map_find(d_map_t *map, const char *key)
{
  d_map_iterator_t *iterator;
  d_map_data_t *data;
  for(iterator = d_map_begin(map); d_map_iterator_valid(iterator);
      d_map_next(&iterator)) {
    d_map_data(iterator, &data);
    if ( ! data->key ) {
      printf("data->key NULL\n");
    }
    if (! key ) {
      printf("key NULL\n");
    }
    if ( ! strcmp(data->key, key)) {
      return iterator;
    }
  }
  return NULL;
}

